<?php
	include_once 'isLogin.php';
	$groupc=new group(); 			//服务类
	$infoc=new info();				//资讯类
	$id=$_GET['id'];				//资讯id
	$smarty->assign('id',$id);
	$table="admin_topic";
	$admin_id=$_COOKIE['admin_id'];

	//修改
	if($id!='' && $id!=null){
		$row=$groupc->topic_info($id);
		$smarty->assign('row',$row);
	}

	//删除
	if($_GET['action']=='del'){
		$tid=$_GET['tid'];				//小编说id
		$res=$commonc->del($table,$tid.',');	
	}

	//小编说
	$where=' and t.info_id="'.$id.'"';
	$key='t.*,from_unixtime(t.create_time,"%Y-%m-%d %H:%m:%s") as createTime,a.name as adminName';
	$topics=$infoc->topicList($where,$key,0);
	$smarty->assign('topics',$topics['result']);

	//添加小编说
	if($_POST['submit']){
		$arr= array('topic' =>$_POST['topic'],);	//话题

		if($id!='' && $id!=null){//update
			$arr['create_time']=time();
			$arr['admin_id']=$admin_id;
			$arr['info_id']=$id;
			$res=$commonc->insert($table,$arr);
			$tid=$commonc->insert_id();		
		}
		
		if($tid){
			$msg="操作成功";
			$href="info_topic.php?id=".$id;
		}else{
			$msg="操作失败";
			$href="info_topic.php?id=".$id;
		}
		echo $commonc->submitAlert($msg,$href);
		exit;
	}


	$smarty->display("info_topic_view.html");
?>